﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Classes.*;

    public class TReplaceUserResource extends TWorldState {

        private var m_oldResourceId:Number;
        private var m_newResourceName:String;
        private var m_isGift:Boolean;
        private var m_isUsingConstruction:Boolean;

        public function TReplaceUserResource(_arg1:String, _arg2:MapResource, _arg3:Boolean=false, _arg4:Boolean=false){
            var _local5:Item;
            super(_arg2);
            this.m_oldResourceId = _arg2.getId();
            this.m_newResourceName = _arg1;
            this.m_isGift = _arg3;
            this.m_isUsingConstruction = _arg4;
            if (!_arg3){
                _local5 = Global.gameSettings.getItemByName(this.m_newResourceName);
                if (_local5.cost > 0){
                    Global.player.gold = (Global.player.gold - _local5.cost);
                } else {
                    if (_local5.cash > 0){
                        Global.player.cash = (Global.player.cash - _local5.cash);
                    } else {
                        GlobalEngine.msg((_local5.name + " cost nothing, make sure this is intentional behavior."));
                    };
                };
                if (_local5.plantXp > 0){
                    Global.player.xp = (Global.player.xp + _local5.plantXp);
                };
            };
        }
        public function get newResourceName():String{
            return (this.m_newResourceName);
        }
        override public function perform():void{
            signedCall("UserService.onReplaceUserResource", Global.world.ownerId, Global.player.uid, this.m_oldResourceId, this.m_newResourceName, this.m_isGift, this.m_isUsingConstruction);
        }

    }
}//package Transactions 
